package com.pbs.ui.dialog;

import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface.OnClickListener;

import com.pbs.ui.R;

public class Dialog {

	public static enum Type {
		ERROR, MESSAGE, WARNING, CONFIRM
	}

	public static AlertDialog show(Context context, String title, String msg, String button1, String button2, OnClickListener button1Click, OnClickListener button2Click, Type type) {
		AlertDialog.Builder builder = new AlertDialog.Builder(context);
		switch (type) {
		case MESSAGE: {
			builder.setIcon(R.drawable.info_icon);
			break;
		}
		case ERROR: {
			builder.setIcon(R.drawable.error_icon);
			break;
		}
		case WARNING: {
			builder.setIcon(R.drawable.warning);
			break;
		}
		case CONFIRM:{
			builder.setIcon(R.drawable.question_icon);
			break;
		}
		}
		if (button1 != null && button1Click != null) {
			builder.setPositiveButton(button1, button1Click);
		}
		if (button2 != null && button2Click != null)
			builder.setNeutralButton(button2, button2Click);

		if (title == null) {
			return builder.setMessage(msg).show();
		} else {
			return builder.setMessage(msg).setTitle(title).show();
		}
	}
	
	public static ProgressDialog showProgressDialog(Context context, String title, String msg, boolean cancelable) {
		ProgressDialog pd = new ProgressDialog(context);
		if (title != null) {
			pd.setTitle(title);
		}
		if (msg != null)
			pd.setMessage(msg);
		pd.setIcon(R.drawable.process_icon);
		pd.setCancelable(cancelable);
		pd.show();
		return pd;
	}
	
	public static ProgressDialog showProgressDialog(Context context, String msg, boolean cancelable) {
		ProgressDialog pd = new ProgressDialog(context);
		if (msg != null)
			pd.setMessage(msg);
		pd.setIcon(R.drawable.process_icon);
		pd.setCancelable(cancelable);
		pd.show();
		return pd;
	}
}
